package com.example.haojiutao.controller.user;

import com.example.haojiutao.common.Result;
import com.example.haojiutao.model.domain.History;

import com.example.haojiutao.service.HistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description: 浏览记录
 * @Author: ma_jun
 * @CreateTime: 2023/12/13 9:47
 */
@RequestMapping("/user/history")
@RestController("UserHistoryController")
public class HistoryController {
    @Autowired
    private HistoryService historyService;
    /*
     * @Description: TODO 插入浏览记录
     * @Author: ma_jun
     * @CreateTime: 2023/12/13 15:49
     * @param: history
     * @return: com.example.treasure_box.common.Result
     **/
    @PostMapping
    public Result insert(@RequestBody History history){
        historyService.insertHistory(history);
        return Result.success("插入成功！");
    }
    /*
     * @Description: TODO 查询浏览记录
     * @Author: ma_jun
     * @CreateTime: 2023/12/13 10:26
     * @return: com.example.treasure_box.common.Result
     **/
    @GetMapping("/{userId}")
    public Result list(@PathVariable Integer userId){
        List<History> histories=historyService.selectAll(userId);
        return Result.success("查询成功！",histories);
    }
    /*
     * @Description: TODO 删除浏览记录
     * @Author: ma_jun
     * @CreateTime: 2023/12/13 10:36
     * @param: id
     * @return: com.example.treasure_box.common.Result
     **/
    @DeleteMapping("/{goodsId}")
    public Result delete(@PathVariable Integer goodsId){
        return historyService.deleteById(goodsId);
    }
}
